
# V1
#
# def shop():
#     x = 1000
#     cartList = []
#     productList = {"手机":900,"洗衣机":800,"鼠标":200,"键盘":300,"音箱":500}
#     print(productList)
#     while True:
#         print("输入要购买的商品名：")
#         product = input()
#         if product in productList:
#             cartList.append(product)
#             if x >= productList[product]:
#                 x -= productList[product]
#                 print(f"恭喜，购买成功！您的卡余额还剩{x}")
#             else:
#                 print("穷鬼，钱不够！请到其他超市购买！")
#         elif product == "q":
#             print(cartList)
#             break
#         else:
#             print("没有这个商品，别瞎弄！")

# V2.0
import datetime
import random
def shop():
    x = 1000
    allmoney = 0
    cartList = []
    z = random.randint(1,10)/10
    print(f"恭喜你，抽到了{z*10}折购物")
    productList = {"手机":900,"洗衣机":800,"鼠标":200,"键盘":300,"音箱":500}
    print(productList)
    while True:
        print("输入要购买的商品名：(输入q/Q退出、w/W退货)")
        product = input()
        if product in productList:
            if x >= productList[product]:
                cartList.append(product)
                x -= productList[product]*z
                print(f"恭喜，购买成功！您的卡余额还剩{x}")
            else:
                print("穷鬼，钱不够！请到其他超市购买！")
        elif product == "q":
            print("打印小票：")
            print("购物时间："+str(datetime.datetime.now()))
            print(f"卡余额：{x}")
            print(cartList)
            for all in cartList:
                allmoney += productList[all]
            print("总消费为"+str(allmoney*z))
            break
        elif product == "w":
            print("输入需要退货名称")
            product = input()
            cartList.remove(product)
            x += productList[product]
            print(f"退货成功卡余额为{x*z}")
        else:
            print("没有这个商品，别瞎弄！")

shop()